home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
GSRC208A.ZIP
/
DATAB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-24
|
26KB
|
845 lines
#include "copyleft.h"
/*
GEPASI - a simulator of metabolic pathways and other dynamical systems
Copyright (C) 1989, 1992 Pedro Mendes
*/
/*************************************/
/* */
/* databases and their functions */
/* */
/* Zortech C/C++ 3.0 r4 */
/* MICROSOFT C 6.00 */
/* Visual C/C++ 1.0 */
/* QuickC/WIN 1.0 */
/* ULTRIX cc */
/* GNU gcc */
/* */
/* (include here compilers that */
/* compiled GEPASI successfully) */
/* */
/*************************************/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef _ZTC
#define MEM_DEBUG 1
#include "mem.h"
#else
#define mem_malloc malloc
#define mem_free free
#define mem_realloc realloc
#endif
#include "globals.h"
#include "globvar.h"
#include "lsoda.h"
#include "strtbl.h"
#include "heapchk.h"
/* structure holding information relative to kinetic mechanisms */
struct kint {
unsigned char nsub; /* number ofsubstrates */
unsigned char npro; /* number of products */
unsigned char nmodf; /* number of modifiers */
unsigned char revers; /* reversability */
unsigned char nconst; /* number of kin. const.*/
char *descr; /* title */
char *constnam; /* kin. constant names */
};
/* structures for user-defined rate equations */
struct nodet{
char item;
unsigned char val;
unsigned char left;
unsigned char right;
} ;
struct treet{
struct nodet node[256];
char id[64][10];
float constant[32];
int nnode,
nnum,
nid,
nsub,
npro,
nmodf,
nconst,
revers;
char descr[64];
} ;
/* structure holding simulation options */
struct opt {
int dyn;
long pfo;
double endtime;
double reltol;
double abstol;
double hrcz;
int adams;
int bdf;
int ss;
int debug;
int txt;
int structan;
int staban;
int stdela;
int nonela;
int stdcc;
int noncc;
int dat;
char datname[PWIDTH];
int datsep;
int datwidth;
int dattit;
int datmca;
int datss;
int append;
int quotes;
char timeu[32];
char concu[32];
int scan;
int scandens;
int scanlog;
};
struct sp{
PDBL var;
double low;
double high;
double ampl;
int dens;
int log;
PDBL linkedto;
double factor;
int operation;
};
PDBL params[MAX_STEP]; /* ptr to parameters for each rate eq. */
int *eff[MAX_STEP]; /* ptr to parameters for each rate eq. */
unsigned char revers[MAX_STEP]; /* 1 if reaction is reversible */
struct opt options; /* structure with simulation options */
struct kint *ktype; /* ptr array of kinetic types & proprt */
struct sp *sparam; /* ptr array with parameters to scan */
PDBL *scanpar; /* ptrs to all possbl.params 4 scanning */
PDBL *outpel; /* ptrs to all possbl. values for output*/
PDBL *poutelem; /* ptrs to values for actual dat output */
char *outtit; /* pointer to buffer with column titles */
char *treestr; /* pointer to buffer with constant names*/
char *treeptr; /* pointer to buffer with constant names*/
int *scindex; /* ptr to base of array with idx to scan*/
int *lindex; /* ptr to base of array with idx 2 links*/
int nscanpar; /* number of scanning elements */
int noutpel; /* number of output elements */
int totscan; /* number of selected scanning params */
int nlinks; /* number of linked parameters */
int nudf; /* number of user-def functions */
int nrateq; /* number of total rate equations */
int totsel; /* number of selected output elements */
int kfl[MAX_STEP]; /* flags for kinetic types */
unsigned int sizespar;
unsigned int sizeparam;
unsigned int sizeeff;
unsigned int sizeoutp;
unsigned int sizetr;
struct treet *tree; /* function tree for rate equations */
struct treet tr; /* tree for the input */
/* main point for memory block allocation */
int MemAlloc( void )
{
int i;
sizeparam = sizeof( double );
params[0] = (double *) mem_malloc( sizeparam );
if( params[0] == NULL ) return -1;
/* make the other params[i] point to NULL */
for( i=1; i<MAX_STEP; i++ ) params[i] = NULL;
sizeeff = 1;
eff[0] = (int *) mem_malloc( sizeeff * sizeof( int ) );
if( eff[0] == NULL )
{
mem_free( params[0] );
return -1;
}
/* make the other eff[i] point to NULL */
for( i=1; i<MAX_STEP; i++ ) eff[i] = NULL;
/* allocate space for the MAX_TYPE descriptors of kinetic types */
ktype = (struct kint *) mem_malloc( MAX_TYP * sizeof( struct kint ) );
if( ktype == NULL )
{
mem_free( params[0] );
mem_free( eff[0] );
return -1;
}
sizeoutp = 4 * sizeof( PDBL );
outpel = (PDBL *) mem_malloc( sizeoutp );
if( outpel == NULL )
{
mem_free( ktype );
mem_free( params[0] );
mem_free( eff[0] );
return -1;
}
poutelem = (PDBL *) mem_malloc( sizeof(PDBL) );
if( poutelem == NULL )
{
mem_free( outpel );
mem_free( ktype );
mem_free( params[0] );
mem_free( eff[0] );
return -1;
}
loop = ( unsigned char (*)[MAX_STEP][MAX_MET] ) mem_malloc( MAX_STEP * MAX_MET * sizeof( unsigned char ) );
if( loop == NULL )
{
mem_free( poutelem );
mem_free( outpel );
mem_free( ktype );
mem_free( params[0] );
mem_free( eff[0] );
return -1;
}
rstr = ( int (*)[MAX_STEP][MAX_MOL] ) mem_malloc( MAX_STEP * MAX_MOL * sizeof( int ) );
if( rstr == NULL )
{
mem_free( loop );
mem_free( poutelem );
mem_free( outpel );
mem_free( ktype );
mem_free( params[0] );
mem_free( eff[0] );
return -1;
}
outtit = ( char * ) mem_malloc( 25 * sizeof( char ) );
if( outtit == NULL )
{
mem_free( rstr );
mem_free( loop );
mem_free( poutelem );
mem_free( outpel );